package com.ch.http.v1.impl;

import com.ch.http.v1.Cookie;

public class CookieImpl implements Cookie {
    String name,value,path,domain;
    Integer maxAge;

    public CookieImpl(String name, String value) {
        this.name = name;
        this.value = value;
    }

    @Override
    public void setDomain(String domain) {
        this.domain = domain;
    }

    @Override
    public void setMaxAge(int maxAge) {
        this.maxAge = maxAge;
    }

    @Override
    public void setPath(String path) {
        this.path = path;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public String getValue() {
        return value;
    }

    public String toString(){
        String s = String.format("%s=%s",getName(),getValue());
        if (domain!=null){
            s+=";domain=" + domain;
        }
        if (maxAge!=null){
            s+=";Max-Age=" + maxAge;
        }
        if (path!=null){
            s+=";path=" +path;
        }
        return s;
    }
}
